<div class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title">商家提现申请</h2>
        <span class="layui-breadcrumb pull-right">
          <a href="#!home">首页</a>
          <a><cite>商家提现申请</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <div class="layui-form toolbar">
            <input id="businesswithdraw-search-value" class="layui-input search-input" type="text" placeholder="输入关键字"/>&emsp;
            <button id="businesswithdraw-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
        </div>

        <table class="layui-table" id="businesswithdraw-table" lay-filter="businesswithdraw-table"></table>
    </div>
</div>


<!-- 表格操作列 -->
<script type="text/html" id="businesswithdraw-table-bar">
 {{#   if(admin.hasPerm("business:businesswithdraw:update") ){   }}
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
 {{#     } }} 
 {{#  if(admin.hasPerm("business:businesswithdraw:delete") ){   }}
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
 {{#     } }} 
</script>

<!--  
<script type="text/html" id="toolbar">
     {{#  if(admin.hasPerm("business:businesswithdraw:save")){ }}
    <button id="businesswithdraw-btn-add" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
     {{#     } }} 
 
</script>
-->
<script type="text/html" id="withdrawStatus">
     {{#    if(d.status==1){ }}
     <button type="button" class="layui-btn layui-btn-normal layui-btn-xs layui-btn-radius">待审核</button>
     {{#     }else if(d.status==2){ }} 
<button type="button" class="layui-btn layui-btn-warm layui-btn-xs layui-btn-radius">已审核</button>
    {{#     }else if(d.status==3){ }} 
 <button type="button" class="layui-btn layui-btn-primary layui-btn-xs layui-btn-radius">已转帐</button>
    {{#     }else if(d.status==-1){ }} 
 <button type="button" class="layui-btn layui-btn-disabled layui-btn-xs layui-btn-radius">驳回</button>
  {{#     } }} 
 
</script>

<script type="text/html" id="withdrawType">
     {{#    if(d.transferType==1){ }}
     <button type="button" class="layui-btn layui-btn-normal layui-btn-xs layui-btn-radius">待转账</button>
     {{#     }else if(d.transferType==2){ }} 
<button type="button" class="layui-btn layui-btn-warm layui-btn-xs layui-btn-radius">线下转帐</button>
    {{#     }else if(d.transferType==3){ }} 
 <button type="button" class="layui-btn layui-btn-primary layui-btn-xs layui-btn-radius">微信转帐</button>
    {{#     }else if(d.transferType==4){ }} 
 <button type="button" class="layui-btn layui-btn-disabled layui-btn-xs layui-btn-radius">银行卡转帐</button>
  {{#     } }} 
 
</script>

<script>
   var admin;
    layui.use(['form', 'table', 'util', 'config', 'admin', 'upload','laytpl','element' ], function () {
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var layer = layui.layer;
        var util = layui.util;
          admin = layui.admin;
        //上传
        var upload = layui.upload;
        let laytpl = layui.laytpl;
        let element = layui.element;

        // 渲染表格
        table.render({
            elem: '#businesswithdraw-table',
            url: config.base_server + 'business/businesswithdraw/list',
            method: 'GET',
       
            page: true,
            cols: [[
                {type: 'numbers'},

                 {field: 'withdrawCode', sort: true, title: '申请编号'},
                 {field: 'bussinesName',   title: '商家'},
                 {field: 'checkUserName',   title: '审核人'},
                 {field: 'transferUserName',  title: '转账人'},
                 {field: 'sum', sort: true, title: '提现金额'},
                 {field: 'poundage', sort: true, title: '手续费'},
                 {field: 'actualSum', sort: true, title: '实际到账'},

                 {field: 'transferTime', sort: true, title: '转账时间'},
                 {field: 'comment', title: '备注'},
                 {fixed: 'right', align: 'center', title: "转帐类型"   ,  toolbar:"#withdrawType" },
                 
                 {fixed: 'right', align: 'center', title: '状态' ,  toolbar:"#withdrawStatus"},
                {fixed: 'right', align: 'center', toolbar: '#businesswithdraw-table-bar', title: '操作', width: 175}
            ]]
        });
        
     /*    laytpl($("#toolbar")[0].innerHTML).render({ }, function(html){
			  $(".layui-card-body .toolbar").append(html);
			  element.render('nav');
		  }); */

        // 添加按钮点击事件
        $('#businesswithdraw-btn-add').click(function () {
            showEditModel();
        });

        // 工具条点击事件
        table.on('tool(businesswithdraw-table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;

            if (layEvent === 'edit') { // 修改
             
                showEditModel(data);
            }  else if (layEvent === 'del') { // 删除
                layer.confirm('确定删除吗？', function (i) {
                    layer.close(i);
                    layer.load(2);
                    admin.req('business/businesswithdraw/delete/'+obj.data.id, {}, function (data) {
                        layer.closeAll('loading');
                        if (data.code == 0) {
                            layer.msg(data.msg, {icon: 1, time: 500});
                            table.reload('businesswithdraw-table', {});
                        } else {
                            layer.msg(data.msg, {icon: 2, time: 500});
                        }
                    }, 'delete');
                });
            }
        });

        //显示表单弹窗
        var showEditModel = function (data) {
        	  var title = data ? '修改备注' : '添加';
            //修改方法名
            if (data){
                data.method="update"
            }else{
            	data={method:"save"};
            }
 
            admin.putTempData('t_businesswithdraw', data);
            admin.popupCenter({
                title: title,
                path: 'pages/business/businesswithdraw_form.html',
                finish: function () {
                    table.reload('businesswithdraw-table', {});
                }
            });
        };

        // 搜索按钮点击事件
        $('#businesswithdraw-btn-search').click(function () {
            var key = $('#businesswithdraw-search-key').val();
            var value = $('#businesswithdraw-search-value').val();
            table.reload('businesswithdraw-table', {where: {searchKey: key, searchValue: value}});
        });

    });
</script>
